var should = require('should');
var app = require('../app');
var request = require('supertest');
var wechat_cfg = require("../wechat-cfg.json");
var wechat = require('node-wechat')(wechat_cfg.Token);


//测试路由，微信接口测试无响应尚未找到原因
describe('router testing', function () {

    it('should return 200 when request index page', function (done) {

    request('http://localhost:3000').get('/index')
    .expect('Content-Type', 'text/html; charset=utf-8')
    .expect(200)
    .end(function(err, res){
        if (err) throw err;

        done();
    });
    });

    it('should return 200 when request chat page', function (done) {

        request('http://localhost:3000').get('/chat')
            .expect('Content-Type', 'text/html; charset=utf-8')
            .expect(200)
            .end(function(err, res){
                if (err) throw err;

                done();
            });
    });

    it('should return 200 when send wechat message',function(done){

        var postData = '<xml><ToUserName><![CDATA[gh_33c9604a7ca0]]></ToUserName>'+
            '<FromUserName><![CDATA[ouYZ0t8_v0HbzeK2PpsL5Aq_YPP0]]></FromUserName>'+
            '<CreateTime>1433918785</CreateTime>'+
            '<MsgType><![CDATA[text]]></MsgType>'+
            '<Content><![CDATA['+ "chat@www.baidu.com" +']]></Content>'+
            '<MsgId>6158634286903385608</MsgId>'+
            '</xml>';



        request('http://localhost:3000').post('/wechat').query({'signature':'e4f5ba201d159cc274e318110d1f792942fe601a',
                                                        'timestamp':'1433912420',
                                                        'nonce':'1405766571'}).send(postData).expect(200).end(function(err,res){
            if (err) throw err;
            console.log('HEADERS: ' + JSON.stringify(res.headers));

            done();
        });
    });
});